﻿#region Using directives

using System;
using System.Collections.Generic;

using Weazel.Badger.Vhdl.Expressions;

#endregion

namespace Weazel.Badger.Vhdl.Statements
{
  public class StatementCollection : SequentialStatement, IStatementCollection
  {
    private List<SequentialStatement> statements = 
			new List<SequentialStatement>();

    private List<string> comments = 
			new List<string>();

    public int Count
    {
      get
      {
        return statements.Count;
      }
    }

		public StatementCollection()
    {
    }

    public void CopyTo(StatementCollection s)
    {
      foreach (SequentialStatement statement in statements)
        s.Add(statement);
    }

    public void InsertFirst(SequentialStatement statement)
    {
      statements.Insert(0, statement);     
    }

    public void InsertAt(int index, SequentialStatement statement)
    {
      statements.Insert(index, statement);
    }

    public void Add(SequentialStatement statement)
    {
      statements.Add(statement);      
    }

    public void Remove(SequentialStatement statement)
    {
      if (statements.Contains(statement))
      {
        statements.Remove(statement);        
      }
    }
    
    public void AddComment(string comment)
    {
      comments.Add(comment);
    }

    public void AddComment(string[] multiLineComment)
    {
      for (int i = 0; i < multiLineComment.Length; i++)
        comments.Add(multiLineComment[i]);
    }

		public override void Resolve(Entity entity, Process process, StatementCollection statements)
    {
      for (int i = 0; i < this.statements.Count; i++)
				this.statements[i].Resolve(entity, process, statements);
    }

    public override void Verify(ref List<VerifyMessage> messages)
    {
      foreach (SequentialStatement statement in statements)
        statement.Verify(ref messages);
    }

    public override void Write(System.CodeDom.Compiler.IndentedTextWriter writer)
    {
      foreach (string comment in comments)
        writer.WriteLine("-- " + comment);

      foreach (SequentialStatement statement in statements)
        statement.Write(writer);
    }
  }
}